import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    tab_bread: [],
    // 消息列表
    message: [{
        id: 1,
        title: "爱上肯德基ask",
        time: "2020-10-18",
        status: 1,
      },
      {
        id: 2,
        title: "爱上大破洞",
        time: "2020-10-18",
        status: 1,
      },
      {
        id: 3,
        title: "【地扶贫赶快】",
        time: "2020-10-18",
        status: 1,
      },
      {
        id: 4,
        title: "大得到哦",
        time: "2020-10-18",
        status: 2,
      },
      {
        id: 5,
        title: "分为of就",
        time: "2020-10-18",
        status: 2,
      },
      {
        id: 6,
        title: "热狗【哦】客人",
        time: "2020-10-18",
        status: 2,
      },
      {
        id: 7,
        title: "二维费",
        time: "2020-10-18",
        status: 3,
      },
      {
        id: 8,
        title: "你水电费涩都发",
        time: "2020-10-18",
        status: 3,
      },
    ]
  }, 
  mutations: {
    addBread(state, bread) {
      //进行逻辑操作，判断路由是否存在，如果存在直接跳过，不存在的进行数据的追加
      //找出路由地址是否重复
      let index = state.tab_bread.findIndex(item => {
        return item.url == bread.url;
      })
      //路由不存在的时候
      if (index == -1) {
        state.tab_bread.push(bread);
      }
    }
  },
  actions: {

  },
  modules: {

  },
  getters: {
    //未读消息数量
    unread(state) {
      let arr = state.message.filter(item => {
        return item.status == 1;
      })
      return arr.length;
    },
    read(state) {
      let arr = state.message.filter(item => {
        return item.status == 2;
      })
      return arr.length;
    },
    removed(state) {
      let arr = state.message.filter(item => {
        return item.status == 3;
      })
      return arr.length;
    }
  }
});